//
//  AppDelegate.swift
//
//  Created by Rdxer on 2017/12/6.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import UIKit
import Device
import XXLogger

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        AppConfig.initConfig()
        configHUD()
        AppDB.setupMainDatabase(application)
        
        UIBarButtonItem.appearance()
            .setTitleTextAttributes([NSAttributedStringKey.font : AUIC.cellTitleSize.toFont], for: .normal)
        
        window = UIWindow.init(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        window?.rootViewController = AppRoutes.shared.lauchAutoChooseVC()
        window?.makeKeyAndVisible()
        
        return true
    }
    
    @available(iOS 9.0, *)
    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        
        let i = AppShortcutItem.makeItem(string: shortcutItem.type)
        
        if let item =  i{
            ShortcutService.shared.addShortcutAction(item: item)
        }else{
            printE("错误... shortcutItem \(shortcutItem.type)")
        }
        
        completionHandler(true)
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
//        CheckUpdateManager.shared.checkIfNeed()
//        if let _ = LoginRequest.current {
//            CheckAccountManager.shared.checkIfNeed()
//        }
    }
    func applicationDidEnterBackground(_ application: UIApplication) {
//        CheckUpdateManager.shared.setNeedCheck()
//        CheckAccountManager.shared.setNeedCheck()
    }
    
    static var sheared:AppDelegate?{
        return UIApplication.shared.delegate as? AppDelegate
    }
}

